﻿function getWindowWidth(){
    if(window.innerWidth) {return window.innerWidth;}
    else if(document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}
    else if(document.body && document.body.clientWidth) {return document.body.clientWidth;}
    else {return 0;}
}

function getWindowHeight(){
    if(window.innerHeight) {return window.innerHeight;}
    else if(document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}
    else if(document.body && document.body.clientHeight) {return document.body.clientHeight;}
    else {return 0;}
}

var _elPageTitle,
    _elPageAuthlite,
    _elMap,
    _elBlogTop,
    _elBlogPost,
    _elBlogRead,
    _elBlogTitle,
    _elBlogLocation,
    _elBlogDescription;
var _elPageTitleHeight = 60;
var _elPageBodyPaneWidth = 300;

function updateLayout() {
    var ww = getWindowWidth();
    var wh = getWindowHeight();

    _elPageTitle.style.height = _elPageTitleHeight + 'px';

    _elPageAuthlite.style.left = (ww - _elPageAuthlite.width.replace('px', '') - 10) + 'px';

    _elMap.style.width =
        ww
        - 20 * 3
        - 15
        - _elPageBodyPaneWidth + 'px';
    
    // set height on maps and blog panes
    _elMap.style.height = 
        _elBlogTop.style.height = 
        _elBlogPost.style.height = 
        _elBlogRead.style.height = 
            wh 
            - _elPageTitleHeight 
            - 2 
            - (20 * 2)
            - 15
            + 'px';
}

function showTop() { 
    _elBlogTop.style.display="block";
    _elBlogRead.style.display =_elBlogPost.style.display = "none";
}
function showRead() {
    _elBlogRead.style.display = "block";
    _elBlogTop.style.display=_elBlogPost.style.display = "none";
}
function showPost() {
    _elBlogPost.style.display = "block";
    _elBlogTop.style.display=_elBlogRead.style.display = "none";
}

function walkDownOneNode(rootnode, tagname) {
    var ar = rootnode.getElementsByTagName(tagname);
    if (ar.length == 1) {
        return ar[0].firstChild.xml;
    } else {
        return null;
    }
}

function bootstrap_layout() {
    _elPageAuthlite = document.getElementById('AuthLite');
    _elPageTitle = document.getElementById('pagetitle');
    
    _elMap = document.getElementById('blogmap');

    _elBlogTop = document.getElementById('blogtop');
    _elBlogPost = document.getElementById('blogpost');
    _elBlogRead = document.getElementById('blogread');

    _elBlogTop.style.width =
        _elBlogPost.style.width = 
        _elBlogRead.style.width = 
            _elPageBodyPaneWidth
            + 'px';

    _elBlogTitle = document.getElementById('blogtitle');
    _elBlogLocation = document.getElementById('bloglocation');
    _elBlogDescription = document.getElementById('blogtext');

    window.attachEvent('onresize', updateLayout);
    updateLayout();
}
    
